package com.liull.papersystem.controller;

import com.liull.papersystem.common.Result;
import com.liull.papersystem.dto.EmployeeDto;
import com.liull.papersystem.dto.QueryEmpReq;
import com.liull.papersystem.entity.Employee;
import com.liull.papersystem.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Descriotion:
 * @Author longlong.liu
 * @Version 1.0
 * @Date 2021/10/27 18:36
 */
@Controller
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/list")
    @ResponseBody
    public Result<List<EmployeeDto>> list(QueryEmpReq req) {
        return Result.success(employeeService.queryEmployeeByPage(req), employeeService.queryEmployeeCount());
    }

    @GetMapping("")
    public String empUi() {
        return "emp/empList";
    }

    @PostMapping("")
    public Result<Object> addEmp(Employee employee) {
        employeeService.addEmp(employee);
        return Result.success();
    }

    @GetMapping("/add/ui")
    public String empAddUi() {
        return "emp/empAdd";
    }
}
